[438] [High] Configurable Protocol Fee Engine with Tiering and Fee Ledger - #551
Merged
Conversation
Pair, chain, and default rules set the fee, referral share, and a balanced debit and credit for each fill. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@Goodnessukaigwe Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
…urable-protocol-fee-engine-with-tiering-and-fee-ledger # Conflicts: # .env.example # CHANGELOG.md # jest.config.js # package-lock.json # package.json # prisma/schema.prisma # src/app.module.ts # src/common/stellar-signature.ts # src/config/configuration.ts # src/config/env.validation.ts # src/governance/governance.module.ts # src/intents/dto/fill-intent.dto.ts # src/intents/intents.controller.ts # src/intents/intents.gateway.spec.ts # src/intents/intents.gateway.ts # src/intents/intents.module.ts # src/intents/intents.service.shadow.spec.ts # src/intents/intents.service.spec.ts # src/intents/solver-intent-matcher.ts # src/intents/ws/connection-state.ts # src/solvers/solvers.controller.ts # src/soroban/event-ingestion.service.ts # src/soroban/signer.service.spec.ts # src/soroban/solver-registry.service.spec.ts # src/soroban/soroban.controller.spec.ts # src/soroban/soroban.module.ts # src/soroban/soroban.service.ts # src/soroban/stellar-tx.service.spec.ts # src/soroban/stellar-tx.service.ts # src/soroban/tx-confirmation.service.ts # src/stats/stats.service.ts # src/tokens/in-memory-tokens.repository.ts # src/tokens/tokens.service.ts # src/treasury/treasury.service.spec.ts # src/treasury/treasury.service.ts # test/jest-e2e.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/fees/with versioned rules. Precedence is specific pair, then source chain, then the built-in 5 bps default. Rules support basis points, min/max caps, and volume tiers. Integrator referral codes take a floored share of the fee; the remainder stays with the treasury.ceil(amount * bps / 10_000)(at most one base unit above truncating division) before caps.QuoteResponseDtoincludestreasuryFee,integratorFee,feeRuleVersion, andreferralCode.Closes #438
Problem
feeAmountwas a flat truncated 5 bps with no rule version, no integrator share, and no ledger to reconcile treasury and integrator balances.Solution
Rules and referrals come from
FEE_RULES_JSONandFEE_REFERRALS_JSON(empty uses the built-in default and no referrals). ADR 0006 records rounding and the ledger invariant. Migration20260929120000_fee_ledgercreatesfee_ledger. The running service posts to an in-memory ledger with that shape, matching the other default memory adapters.Test plan
feeRuleVersionis 1, andintegratorFeeis 0feeAmountmatches the quoteMade with Cursor